{extend name="base"/}
 {block name="content"}
<div id="dcWrap">
 {include file="public:header" /}

<!-- dcHead 结束 --> 
{include file="public:nav" /}
 <div id="dcMain">
   <!-- 当前位置 -->
<div id="urHere">DouPHP 管理中心<b>></b><strong>首页轮播图</strong> </div>   <div class="mainBox imgModule">
    <h3>首页轮播图</h3>
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
    <tr>
       <th>添加轮播图</th>
       <th>轮播图列表</th>
     </tr>
     <tr>
      <td width="350" valign="top">
       <form action="" method="post" id="caro_data" enctype="multipart/form-data">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableOnebor">
         <tr>
          <td><b>轮播图名称</b>
			<input type="text" id="caro_name" name="caro_name" value="" size="20" class="inpMain" />
			<font style="display:none" class="adcaro_name" color='red'>名称不能未空</font>
          </td>
         </tr>
         <tr>
          <td>
		  <!--lay上传图片-->
		  <a class="layui-btn" id="image" style="float: left;"><i class="layui-icon">&#xe67c;</i>上传轮播图片</a>
			<img style="margin-left: 110px;" id="img" src="/uploads/20170929/4d4dfd00c0d9d1d29fd76b119c71d81a.jpg" width="500" height="140">
			<input type="hidden" id="caro_img" name="caro_img" value=""/>
			<font style="display:none" class="adcaro_img" color='red'>请上传图片</font>	
		   </td>
         </tr>
         <tr>
          <td><b>排序</b>
			<input type="text" name="caro_sort" id="caro_sort" value="" size="20" class="inpMain" />
			<font style="display:none" class="adcaro_sort" color='red'>排序不能为空</font>	
          </td>
         </tr>
         <tr>
          <td>
                      <input type="hidden" name="token" value="79db104d" />
			<input type="button" onclick='caro_add()' value="提交" class="btn"/>
          </td>
         </tr>
        </table>
       </form>
      </td>
      <td valign="top">
       <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableOnebor">
        <tr>
         <td width="100">首页轮播图</td>
         <td width="100">首页轮播图名称</td>
         <td width="50" align="center">排序</td>
         <td width="80" align="center">操作</td>
        </tr>
		{foreach name="carodata" item="vo"}
                <tr>
         <td><a href="{$vo['caro_img']}" target="_blank"><img src="{$vo['caro_img']}" width="500" height="140" /></a></td>
         <td>{$vo['caro_name']}</td>
         <td align="center">{$vo['caro_sort']}</td>
         <td align="center"><a href="{:url('admin/imgclass/edit_carousel',['caro_id'=>$vo['caro_id']])}">编辑</a> | <a href="JavaScript:" onclick="caro_dele('确定要下架吗？',{$vo['caro_id']})">下架</a></td>
        </tr>
         {/foreach}       
               </table>
              <h3 align="center">{$carodata[0]?'':'这里没有数据'}</h3>  
      </td>
     </tr>
    </table>
   </div>
 </div>
 <div class="clear"></div>
 <script>
 //上传图片
layui.use('upload',function(){
  var upload = layui.upload,
  jq = layui.jquery;
  upload.render({
	url: '{:url("admin/imgclass/upload")}'
	,elem:'#image'
	,ext: 'jpg|png|gif'
	,area: ['500', '500px']
	,done: function(res){
	jq('input[name=img]').val(res.path);
	img.src = ""+res.path;
	$("#caro_img").val(res.path);
	}
  }); 

})
//提交
$(function(){
	$("#car_name").blur(function(){
	$(".adcar_name").hide();
	})
	$("#caro_img").blur(function(){
	$(".adcaro_img").hide();
	})
	$("#caro_sort").blur(function(){
	$(".adcaro_sort").hide();
	})

})
function caro_add(){
	var success_url="{:url('admin/imgclass/in_carousel')}";
	var url="{:url('admin/imgclass/caro_add')}";
	var admins=$("#caro_data").serialize();
	//alert(admins);
	var caro_name=$("#caro_name").val();
	var caro_img=$("#caro_img").val();
	var caro_sort=$("#caro_sort").val();
	if(caro_name.length<1){
	$(".adcaro_name").show();
	}else if(caro_img.length<1){
	$(".adcaro_img").show();
	}else if(caro_sort.length <1){
	$(".adcaro_sort").show();
	}else{
	$.post(url,admins,function(result)
	{	 
	if(result.status=='4')
		{
		dialog.success(result.message,success_url);
		}else
		{
			dialog.error(result.message);
		} 
		})
	}

}
//删除轮播图
function caro_dele(message, id) {
        layer.open({
            content : message,
			
            icon:3,
            btn : ['是','否'],
            yes : function(){
                var url="{:url('admin/imgclass/caro_dele')}";
				var success_url="{:url('admin/imgclass/in_carousel')}";
				$.post(url,{'caro_id':id},function(result){
				if(result.status=='1')
					{
					dialog.success(result.message,success_url);
					}else
					{
						dialog.error(result.message);
					} 
				})
            }
        });
    }
</script>
{/block}